import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart' hide Action;

import 'action.dart';
import 'state.dart';

Reducer<EditViewState> buildReducer() {
  return asReducer(
    <Object, Reducer<EditViewState>>{
      EditViewAction.action: _onAction,
      EditViewAction.setValue: _setValue,
    },
  );
}

EditViewState _onAction(EditViewState state, Action action) {
  final EditViewState newState = state.clone();
  return newState;
}

EditViewState _setValue(EditViewState state, Action action) {
  final EditViewState newState = state.clone();
  newState.controller.value = TextEditingValue(text: action.payload);
  return newState;
}
